home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 3.6 KB | 119 lines | [TEXT/CWIE] |
- //========================================================================================
- //
- // File: Behavior.cpp
- // Release Version: $ ODF 2 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef BEHAVIOR_H
- #include "Behavior.h"
- #endif
-
- #ifndef FWSESION_H
- #include "FWSesion.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- // ----- OpenDoc -----
-
- #ifndef SOM_ODFocusSet_xh
- #include <FocusSet.xh>
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- //========================================================================================
- // Runtime information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfbutton
- #endif
-
- //========================================================================================
- // class COptionBehavior
- //========================================================================================
-
- FW_DEFINE_AUTO(COptionBehavior)
-
- //----------------------------------------------------------------------------------------
- // COptionBehavior::COptionBehavior
- //----------------------------------------------------------------------------------------
-
- COptionBehavior::COptionBehavior(Environment* ev) :
- FW_MEventHandler(ev, NULL, FW_kNoPriority),
- fEmptyFocusSet(NULL),
- fFullFocusSet(NULL),
- fCurrentFocusSet(NULL)
- {
- // - fEmptyFocusSet will be used to handle simple clicks
- // - fFullFocusSet will be used to select the button as an embedded frame
- ODArbitrator* arbitrator = FW_CSession::GetArbitrator(ev);
- fEmptyFocusSet = arbitrator->CreateFocusSet(ev);
-
- fFullFocusSet = arbitrator->CreateFocusSet(ev);
- fFullFocusSet->Add(ev, FW_CPart::fgKeyFocusToken);
- fFullFocusSet->Add(ev, FW_CPart::fgMenuFocusToken);
- fFullFocusSet->Add(ev, FW_CPart::fgSelectionFocusToken);
- fFullFocusSet->Add(ev, FW_CPart::fgClipboardFocusToken);
-
- fDesiredFocusSet = fEmptyFocusSet;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // COptionBehavior::~COptionBehavior
- //----------------------------------------------------------------------------------------
-
- COptionBehavior::~COptionBehavior()
- {
- FW_START_DESTRUCTOR
-
- // Do not delete the fCurrentFocusSet, it is owned by the frame
- if (fCurrentFocusSet != fFullFocusSet)
- delete fFullFocusSet;
-
- if (fCurrentFocusSet != fEmptyFocusSet)
- delete fEmptyFocusSet;
- }
-
- //----------------------------------------------------------------------------------------
- // COptionBehavior::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Handled COptionBehavior::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_Boolean optionPressed = theMouseEvent.IsCopyModifier(ev);
-
- // Switches focus set on the fly to allow selection of the button when it's an
- // embedded frame.
- fDesiredFocusSet = optionPressed ? fFullFocusSet : fEmptyFocusSet;
-
- return optionPressed ? FW_kHandled : FW_kNotHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // COptionBehavior::GetDesiredFocusSet
- //----------------------------------------------------------------------------------------
-
- ODFocusSet* COptionBehavior::GetDesiredFocusSet()
- {
- fCurrentFocusSet = fDesiredFocusSet;
- fDesiredFocusSet = fEmptyFocusSet; // So next time it will be empty unless user uses Option key
- return fCurrentFocusSet;
- }
-